﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BotonJXC.DAO;
using NHibernate;
using BotonJXC.Entity;
using NHibernate.Criterion;
using BotonJXC.Util;

namespace BotonJXC.BLL
{
    public class FinanceBillsDAO : NHibernateDao<FinanceBills, int>
    {
        public void SaveFinance(FinanceBills FinanceBills)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {

                base.Save(FinanceBills);
                trans.Commit();
            }
            catch (HibernateException ex)
            {
                trans.Rollback();
                throw;

            }
            finally
            {
                HBHelper.Close();
            }

        }

        public void Modify(FinanceBills FinanceBills)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {

                base.Update(FinanceBills);
                trans.Commit();
            }
            catch (HibernateException ex)
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                HBHelper.Close();
            }

        }
        public void DeleteFinance(FinanceBills FinanceBills)
        {
            ITransaction trans = HBHelper.BeginTransaction();
            try
            {
                //  base.Delete(pip.PriceInfo.PriceInfoId);
                base.Delete(FinanceBills);
                trans.Commit();
            }
            catch (HibernateException ex)
            {
                trans.Rollback();
                throw;
            }
            finally
            {
                HBHelper.Close();
            }
        }

        public PageModel<FinanceBills> FindPage(FinanceBills FinanceBills, int start, int count)
        {
            List<ICriterion> criterions = new List<ICriterion>();
            if (FinanceBills!=null) {
                if (Utils.IsNotBlank(FinanceBills.FinaBillSn))
                {
                    criterions.Add(Restrictions.Eq("FinaBillSn", FinanceBills.FinaBillSn));
                }
                if (Utils.IsNotBlank(FinanceBills.AccOptSign))
                {  //new PriceInfo().Account.Username
                    criterions.Add(Restrictions.Eq("AccOptSign", FinanceBills.AccOptSign));
                }
                if (Utils.IsNotBlank(FinanceBills.AuditStatus))
                {
                    criterions.Add(Restrictions.Eq("AuditStatus", FinanceBills.AuditStatus));
                }
            }
 
            Order order = new Order("FinaBillId", false);
            return base.FindByPage(criterions.ToArray(), order, start, count);
        }
    }
}
